clear all
set more off
tempfile ubigeo temp

/* 

This dofile matches the violence registered in the cell district-year to the cell district-year of age y of each individual.

For instance, first we define what year was when the individual was 5 years old. For a 30 years old individual in the 2007 wave of the survey this was 1982. We attach the violence registered in 1982 in her district of birth. 
This process goes from age 0 to 65

Type of violence: government 

Time period: only 80s

*/

** PATHS
local working ../working

** DATA
use `working'/200, clear

local n = 0
forvalues y = 0/65 {
	gen yearviolence = year - age + `n'
	replace yearviolence = . if `n' > age
	
	merge m:1 ubigeonac1993 yearviolence using `working'/violenceA80
	drop if _merge == 2
	drop _merge
	
	rename events eventsA80`y'
	*rename terrorists terrorists`y'
	*rename government government`y'
	
	drop yearviolence
	local ++n
}

recode events* /*terrorists* government**/ (. = 0)

keep conglome vivienda hogar codperso year events* //terrorists* government*
compress
save `working'/attachviolenceA80, replace
